
package jh.com.jhappbf.weight.query;


import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.RelativeLayout;
import android.widget.TextView;

import androidx.fragment.app.Fragment;
import jh.com.jhappbf.R;
import jh.com.jhappbf.model.SettingModel;

/**
 * @author Administrator
 */
public class QueryMain extends Fragment implements OnClickListener {
    private SettingModel mSettingModel;
    private final int SETTING = 0X0001;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View v = inflater.inflate(R.layout.query_weight_main_activity, null);
        initView(v);
        return v;
    }

    /**
     * 初始化
     */
    private void initView(View v) {
        RelativeLayout mRLayoutDay = v.findViewById(R.id.query_weight_day_layout);
        RelativeLayout mRLayoutMonth = v.findViewById(R.id.query_weight_month_layout);
        RelativeLayout mRLayoutYear = v.findViewById(R.id.query_weight_year_layout);
        RelativeLayout mRLayoutSetting = v.findViewById(R.id.query_weight_setting_layout);
        RelativeLayout mRLayoutDao= v.findViewById(R.id.query_weight_dao_layout);
        RelativeLayout mRLayoutLing = v.findViewById(R.id.query_weight_ling_layout);
        TextView mTxtDay = v.findViewById(R.id.query_weight_day_txt);
        TextView mTxtMonth = v.findViewById(R.id.query_weight_month_txt);
        TextView mTxtYear = v.findViewById(R.id.query_weight_year_txt);
        TextView mTxtSetting = v.findViewById(R.id.query_weight_setting_txt);
        TextView mTxtDao = v.findViewById(R.id.query_weight_dao_txt);
        TextView mTxtLing = v.findViewById(R.id.query_weight_ling_txt);

        mRLayoutDay.setOnClickListener(this);
        mTxtDay.setOnClickListener(this);

        mRLayoutDao.setOnClickListener(this);
        mTxtDao.setOnClickListener(this);

        mRLayoutLing.setOnClickListener(this);
        mTxtLing.setOnClickListener(this);

        mRLayoutMonth.setOnClickListener(this);
        mTxtMonth.setOnClickListener(this);

        mRLayoutYear.setOnClickListener(this);
        mTxtYear.setOnClickListener(this);

        mRLayoutSetting.setOnClickListener(this);
        mTxtSetting.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.query_weight_dao_layout:
            case R.id.query_weight_dao_txt:    //内倒查询
                Intent i = new Intent(getActivity(), QueryWeight.class);
                i.putExtra("flag", "dao");
                i.putExtra("data", mSettingModel);
                startActivity(i);
                break;
            case R.id.query_weight_ling_layout:
            case R.id.query_weight_ling_txt:    //零售查询
                Intent i4 = new Intent(getActivity(), QueryWeight.class);
                i4.putExtra("flag", "ling");
                i4.putExtra("data", mSettingModel);
                startActivity(i4);
                break;
            case R.id.query_weight_day_layout:
            case R.id.query_weight_day_txt:    //采购查询
                Intent i5 = new Intent(getActivity(), QueryWeight.class);
                i5.putExtra("flag", "buy");
                i5.putExtra("data", mSettingModel);
                startActivity(i5);
                break;
            case R.id.query_weight_month_layout:
            case R.id.query_weight_month_txt://销售查询
                Intent i1 = new Intent(getActivity(), QueryWeight.class);
                i1.putExtra("flag", "sale");
                i1.putExtra("data", mSettingModel);
                startActivity(i1);

//                Intent i3 = new Intent(getActivity(), QuerySetting.class);
//                i3.putExtra("data", mSettingModel);
//                startActivityForResult(i3, SETTING);
                break;
            case R.id.query_weight_year_layout:
            case R.id.query_weight_year_txt:
                Intent i2 = new Intent(getActivity(), QueryWeight.class);
                i2.putExtra("flag", "out");
                i2.putExtra("data", mSettingModel);
                startActivity(i2);
                break;
            case R.id.query_weight_setting_layout:
            case R.id.query_weight_setting_txt:
                Intent i3 = new Intent(getActivity(), QuerySetting.class);
                i3.putExtra("data", mSettingModel);
                startActivityForResult(i3, SETTING);
                break;
            default:
                break;
        }
    }

    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode == SETTING) {
            if (data != null) {
                mSettingModel = data.getParcelableExtra("result");
            }
        }
    }
}
